#include "../sys/list.h"
#include "../sys/string.h"
#include "../sys/wtime.h"

#include <time.h>

typedef struct inode_
{
	struct inode_ *next;
	struct inode_ *prev;
	int            data;
} inode_t;

int main(int argc, char *argv[] )
{
	mds_wtime wt;
	mds_wtime_init( &wt );
	mds_wtime_start( &wt );
	{
		size_t        i      = 0;
		const size_t  num    = 20;
		mds_list      list   = { NULL, NULL, 0 };
		inode_t      *nodes  = MDS_CALLOC_AS(inode_t,num);
		inode_t      *node;
		
		if( !nodes )
		{
			mds_perror( stderr, "couldn't allocate nodes!");
			return -1;
		}
		
		srand( time(NULL) );
		
		for( i=0; i < num; ++i )
		{
			node = nodes+i;
			node->data = i;
			if( rand() > RAND_MAX/2 )
			{
				mds_list_push_back(&list, node);
			}
			else 
			{
				mds_list_push_front(&list, node);
			}
			
		}
		
		fprintf( stderr, "list size=%u\n", (unsigned)(list.size) );
		for( node = (inode_t *)(list.head); node; node=node->next )
		{
			fprintf( stderr, "data=%d\n", node->data);
		}
		
		MDS_FREE_AS(inode_t,nodes,num);
		
	}
	
	
	{
		char *str = mds_string_create(10);
		if( str )
		{
			fprintf( stderr, "str length= %u \n", (unsigned) mds_string_length(str) );
			mds_string_delete(str);
		}
	}
	
	
	fprintf( stderr, "done in %.6f ms\n", 1000*mds_wtime_query( &wt ) );
	
	return 0;
}
